package org.example;

public class Test2 {
    //leetcode 283 移动零
    //https://leetcode.cn/problems/move-zeroes/

    /**
     *
     * 通过slow和fast指针，将数组分为三个部分
     * [0,slow]非零元素，(slow,fast]为零元素，(fast,len-1]为待遍历元素
     * @param nums
     */
    public void moveZeroes(int[] nums) {
        for (int slow = -1, fast = 0; fast < nums.length; fast++) {
            if (nums[fast] != 0) {
                int tmp = nums[++slow];
                nums[slow] = nums[fast];
                nums[fast] = tmp;
            }
        }
    }
}
